Test: add unit tests for ClinicController#175
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded a new Spring MVC web-layer test class Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/test/java/org/example/vet1177/controller/ClinicControllerTest.java (1)
28-51: Add one validation-failure test for@Validrequest constraints.Current coverage is only the happy path. Add a bad-request case (e.g., blank
name) to verify controller validation behavior.Suggested additional test
+ `@Test` + void shouldReturnBadRequestWhenNameIsBlank() throws Exception { + String json = """ + { + "name": "", + "address": "Street", + "phoneNumber": "123" + } + """; + + mockMvc.perform(post("/api/clinics") + .contentType("application/json") + .content(json)) + .andExpect(status().isBadRequest()); + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/org/example/vet1177/controller/ClinicControllerTest.java` around lines 28 - 51, Add a new test in ClinicControllerTest that posts an invalid Clinic JSON (e.g., "name": "" or missing) to the same "/api/clinics" endpoint to assert validation fails: perform mockMvc.perform(post("/api/clinics")...).contentType("application/json").content(invalidJson)) and expect status().isBadRequest(); also verify clinicService.create(...) was not invoked (use verify(clinicService, never()).create(...)) to ensure the controller's `@Valid` constraints short-circuit processing. Place this alongside shouldCreateClinic() and name it something like shouldReturnBadRequestWhenNameBlank().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/test/java/org/example/vet1177/controller/ClinicControllerTest.java`:
- Line 33: The test currently stubs clinicService.create with
when(clinicService.create(any(), any(), any())).thenReturn(clinic), which masks
incorrect argument mapping; change the stubbing to use exact expected values
(e.g., when(clinicService.create(eq(expectedName), eq(expectedAddress),
eq(expectedOwner))).thenReturn(clinic)) or remove the stub and use an
ArgumentCaptor to capture the actual arguments passed to clinicService.create in
ClinicControllerTest, then assert those captured values equal the expected
request fields and add verify(clinicService).create(...) to ensure it was
invoked once with the correct arguments.
---
Nitpick comments:
In `@src/test/java/org/example/vet1177/controller/ClinicControllerTest.java`:
- Around line 28-51: Add a new test in ClinicControllerTest that posts an
invalid Clinic JSON (e.g., "name": "" or missing) to the same "/api/clinics"
endpoint to assert validation fails: perform
mockMvc.perform(post("/api/clinics")...).contentType("application/json").content(invalidJson))
and expect status().isBadRequest(); also verify clinicService.create(...) was
not invoked (use verify(clinicService, never()).create(...)) to ensure the
controller's `@Valid` constraints short-circuit processing. Place this alongside
shouldCreateClinic() and name it something like
shouldReturnBadRequestWhenNameBlank().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9fbd61a6-85d1-46ca-9f33-a07b3f647461
📒 Files selected for processing (1)
src/test/java/org/example/vet1177/controller/ClinicControllerTest.java
…e mapping Use explicit argument matching instead of any() and verify that the controller invokes ClinicService with the correct values.
Summary by CodeRabbit